<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/14
 * Time: 13:08
 */
namespace app\api\model;
use think\Controller;
use think\Model;
use think\Db;
use app\api\model\Hotel;
class OrderDetails extends model
{
    /**
     * @param $order_id
     * @param $order_status
     */
    public function orderDetails($order_id,$type)
    {
        if($type==1){
            $res = Db::name('tour_order')->alias('to')
                ->join('tours t','to.tour_id=t.tour_id','LEFT')
                ->join('tour_ticket tt','tt.tid=to.type_id','LEFT')
                ->field('to.order_id,to.tour_id as id,to.order_sn,to.linkman,to.tel,to.ticket_date as time,to.order_status,to.order_price,to.ticket_count as number,t.tour_name as title,to.create_time,tt.tname,tt.can_refund as is_quxiao,to.cancel_code')
                ->where('to.order_id',$order_id)
                ->find();
            //处理时间
            $res['time'] = date('Y-m-d',$res['time']);
            $res['create_time'] = date('Y-m-d H:i:s',$res['create_time']);
            $res['room_name'] = '';
            unset($res['can_refund']);
        }

        if($type==2){
            $res =  Db::name('hotel_order')->alias('ho')
                ->join('hotel h','ho.hotel_id=h.hotel_id','LEFT')
                ->join('hotel_room r','ho.room_id=r.room_id','left')
                ->field('ho.order_id,ho.hotel_id as id,ho.order_sn,ho.room_name,ho.linkman,ho.tel,ho.room_amount as number,ho.create_time,ho.order_price,ho.order_status,ho.start_time,ho.end_time,h.hotel_name as title,r.is_quxiao,ho.cancel_code')
                ->where('ho.order_id',$order_id)
                ->find();
            $res['time'] = date('Y-m-d',$res['start_time'])."至".date('Y-m-d',$res['end_time']);
            $res['create_time'] = date('Y-m-d H:i:s',$res['create_time']);
            $res['tname'] = "";
            unset($res['start_time']);
            unset($res['end_time']);
        }

        if($type==3){
            $res = Db::name('gtour_order')->alias('go')
                ->join('group_tour gt','go.gtour_id=gt.id','LEFT')
                ->join('team t','t.team_id=gt.team_id','left')
                ->field('go.order_id,go.gtour_id as id,go.order_sn,go.gtour_number as number,go.linkman,go.tel,go.gtour_start as time,go.order_price,go.order_status,go.create_time,gt.gtour_title as title,gt.is_quxiao,go.cancel_code')
                ->where('go.order_id',$order_id)
                ->find();
            $res['time'] = date('Y-m-d',$res['time']);
            $res['create_time'] = date('Y-m-d H:i:s',$res['create_time']);
            $res['room_name'] = '';
            $res['tname'] = '';
        }

//        if($type==4){
//           $res =  Db::name('guide_order')->alias('go')
//                ->join('guide g','go.guide_id=g.guide_id','LEFT')
//                ->field('go.order_id,go.guide_id,go.order_sn,go.is_car,go.rename,go.phone,go.pay_type,go.order_price,go.order_status,go.create_time,go.start_time,go.end_time,g.name,g.guide_tel')
//                ->where('go.order_id',$order_id)
//                ->find();
//           $res['start_time'] = date('Y-m-d',$res['start_time']);
//           $res['end_time'] = date('Y-m-d',$res['end_time']);
//           $res['create_time'] = date('Y-m-d H:i:s',$res['create_time']);
//           $res['type'] = 4;
//        }
        return $res;
    }
}